package com.tg.app.activity.device;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tange.core.device.talk.DeviceTalkback;
import com.tange.core.media.source.impl.live.LiveResolutions;
import com.tange.core.universal.instructions.AwakeInstruction;
import com.tg.app.activity.base.CameraBaseActivity;
import com.tg.app.camera.AVIOCTRLDEFs;
import com.tg.app.helper.DeviceHelper;
import com.tg.appcommon.android.TGLog;

import java.util.ArrayList;
import java.util.List;


public class LiveActivity extends CameraBaseActivity {
    protected FrameLayout playerContainer;
    protected View ptzContainer;
    protected RelativeLayout recordTimeLayout;
    protected TextView recordTimeText;
    final List<LiveResolutions> resolutions = new ArrayList<>();
    protected int currentResolution = AVIOCTRLDEFs.AVIOCTRL_QUALITY_MIN;
    protected boolean hasAudioPermission;
    protected DeviceTalkback deviceTalkback = null;
    protected AwakeInstruction awakeInstruction;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    protected void keepAwake(){
        if (DeviceHelper.isBatteryDevice(mDevice)){
            if (awakeInstruction == null){
                awakeInstruction = new AwakeInstruction(deviceFacade);
            }
            awakeInstruction.keepAwake(ret -> {
                if (ret.getSuccess()) {
                    TGLog.i(TAG, "keepAwake success");
                }else {
                    TGLog.i(TAG, "keepAwake failed");
                }
            });
        }
    }

    private void leaveAwake(){
        if (DeviceHelper.isBatteryDevice(mDevice)){
            if (awakeInstruction == null){
                awakeInstruction = new AwakeInstruction(deviceFacade);
            }
            awakeInstruction.leaveAwake(ret -> {
                if (ret.getSuccess()) {
                    TGLog.i(TAG, "leaveAwake success");
                }else {
                    TGLog.i(TAG, "leaveAwake failed");
                }
            });
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        leaveAwake();
    }


}
